package com.qiyi.player.core.model.remote
{
   import com.qiyi.player.base.rpc.impl.BaseRemoteObject;
   import com.qiyi.player.core.player.coreplayer.ICorePlayer;
   import com.qiyi.player.base.logging.ILogger;
   import flash.net.URLRequest;
   import com.qiyi.player.core.Config;
   import flash.events.Event;
   import com.qiyi.player.core.model.impls.SkipPointInfo;
   import flash.utils.clearTimeout;
   import com.adobe.serialization.json.JSON;
   import com.qiyi.player.core.model.def.SkipPointEnum;
   import com.qiyi.player.base.rpc.RemoteObjectStatusEnum;
   import com.qiyi.player.base.logging.Log;
   
   public class RequestEnjoyableSkipPointsRemote extends BaseRemoteObject
   {
      
      public function RequestEnjoyableSkipPointsRemote(param1:ICorePlayer, param2:String) {
         this._log = Log.getLogger("com.qiyi.player.core.model.actors.RequestEnjoyableSkipPointsRemote");
         super(0,"RequestEnjoyableSkipPointsRemote");
         _retryMaxCount = Config.requestSkipPointsMaxRetry;
         _timeout = Config.requestSkipPointsTimeout;
         this._holder = param1;
         this._tvid = param2;
         this._skipPointTypeArr = [];
         this._skipPointArr = [];
         this._skipPointInfoDurationArr = [];
      }
      
      private var _holder:ICorePlayer;
      
      private var _skipPointTypeArr:Array;
      
      private var _skipPointArr:Array;
      
      private var _skipPointInfoDurationArr:Array;
      
      private var _tvid:String;
      
      private var _log:ILogger;
      
      public function get skipPointTypeArr() : Array {
         return this._skipPointTypeArr;
      }
      
      public function get skipPointArr() : Array {
         return this._skipPointArr;
      }
      
      public function get skipPointInfoDurationArr() : Array {
         return this._skipPointInfoDurationArr;
      }
      
      override protected function getRequest() : URLRequest {
         var _loc1_:* = Config.ENJOYABLE_SKIP_POINT_URL + this._tvid + "/";
         return new URLRequest(_loc1_);
      }
      
      override protected function onComplete(param1:Event) : void {
         var json:Object = null;
         var arr1:Array = null;
         var j:int = 0;
         var item:Object = null;
         var arr2:Array = null;
         var skipPointInfo:SkipPointInfo = null;
         var skipPointVec:Vector.<SkipPointInfo> = null;
         var i:int = 0;
         var event:Event = param1;
         clearTimeout(_waitingResponse);
         _waitingResponse = 0;
         try
         {
            _data = _loader.data;
            if(!(_data == null) && !(_data == ""))
            {
               json = com.adobe.serialization.json.JSON.decode(_data as String);
               if(json.code == "A00000")
               {
                  arr1 = json.data as Array;
                  if((arr1) && arr1.length > 0)
                  {
                     j = 0;
                     while(j < arr1.length)
                     {
                        item = arr1[j];
                        if(item)
                        {
                           arr2 = item.data as Array;
                           if((arr2) && arr2.length > 0)
                           {
                              this._skipPointInfoDurationArr.push(int(item.t) * 1000);
                              if(item.gender == 1)
                              {
                                 this._skipPointTypeArr.push(SkipPointEnum.ENJOYABLE_SUB_MALE);
                              }
                              else if(item.gender == -1)
                              {
                                 this._skipPointTypeArr.push(SkipPointEnum.ENJOYABLE_SUB_FEMALE);
                              }
                              else
                              {
                                 this._skipPointTypeArr.push(SkipPointEnum.ENJOYABLE_SUB_COMMON);
                              }
                              
                              skipPointInfo = null;
                              skipPointVec = new Vector.<SkipPointInfo>();
                              i = 0;
                              while(i < arr2.length)
                              {
                                 item = arr2[i];
                                 if(item)
                                 {
                                    skipPointInfo = new SkipPointInfo();
                                    if(int(item.type) == 1)
                                    {
                                       skipPointInfo.skipPointType = SkipPointEnum.ENJOYABLE;
                                    }
                                    skipPointInfo.startTime = int(item.start) * 1000;
                                    skipPointInfo.endTime = int(item.end) * 1000;
                                    skipPointVec.push(skipPointInfo);
                                 }
                                 i++;
                              }
                              this._skipPointArr.push(skipPointVec);
                           }
                        }
                        j++;
                     }
                  }
               }
               else
               {
                  this._log.debug("RequestEnjoyableSkipPointsRemote result code: " + json.code);
               }
            }
            else
            {
               this._log.debug("RequestEnjoyableSkipPointsRemote result is empty!");
            }
            super.onComplete(event);
         }
         catch(e:Error)
         {
            _log.debug("RequestEnjoyableSkipPointsRemote result DataError!");
            setStatus(RemoteObjectStatusEnum.DataError);
         }
      }
   }
}
